/*
** Konami Thunder Cross
** This driver can also run Super Contra.
**
** TODO: move this into k7232drv.cpp
*/

#include "smse2kincludes.h"
#include "SoundDeviceFactory.h"
#include "CPUFactory.h"
#include "TXMMU.h"
#include "TXDriver.h"

int CTXDriver::Load(const char* fn) {
	//FILE_HANDLE rom = filesystem.OpenFile("775-c01.bin",FSYS_PERMISSION_READ);
	FILE_HANDLE rom = filesystem.OpenFile("873-f01.f8",FSYS_PERMISSION_READ);

	if (rom) filesystem.Read(rom,this->ThunderXRom,0x8000);
	else return 1;

	Msg("Load completed\n");
	return 0; // Everything's loaded already
}

int CTXDriver::Init(CHardware* hardware) {
	
	z80 = CPUFactory("Z80");
	z80->Init(3579545);
	z80->AssignMMU(0,&mmu);

	ym = SoundDeviceFactory("YM2151");
	ym->Init(hardware->mixer,3579545);
	memset(mmu.memspace,0,0xffff);
	memcpy(mmu.memspace,ThunderXRom,0x8000);


	// Fine without interleaving
	hardware->ChangeScheduler(1.0/480.0,1.0/480.0);

	mmu.ym = ym;

	hardware->AddCpu(z80);
	hardware->AddSound(ym);

	return 0;
};

int IsInitCodeSent = 0;

void CTXDriver::SetSubsong(int song) {
	mmu.memspace[0xa000] = 0x85;
	z80->Interrupt(0,HOLD_LINE);
}

void CTXDriver::Close() {

}

void CTXDriver::FreeUnusedResources() {

}

DRIVER_DOES_NOT_SUPPORT_FILETYPES(CTXDriver);
DRIVER_FACTORY("thunderx","Thunder Cross test driver",1,CTXDriver);